package com.endurance.controller;

import com.endurance.entity.Dept;
import org.apache.tomcat.jni.Time;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.web.bind.annotation.*;

import javax.xml.crypto.Data;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;

/**
 * @ProjectName: spring-cloud-hoxton-parent
 * @Package: com.endurance.controller
 * @ClassName: DeptController
 * @Description:
 * @Author: sunlin
 * @CreateDate: 2024/02/05 09:00
 * @Version: 1.0
 */

@RestController
@RequestMapping("/dept")
public class DeptController {

    @Value("${server.port}")
    private String port;

    @GetMapping
    public String dept() {
        System.out.println("员工接口");
        return "dept-ok:" + port;
    }

    @GetMapping("getReturnList")
    public List<Dept> getReturnList(String dept) throws InterruptedException {
        System.out.println(dept);
        List<Dept> depts = new ArrayList<>();
        Thread.sleep(1000);
        depts.add(new Dept(1, "部门1", new Date()));
        depts.add(new Dept(2, "部门2", new Date()));
        depts.add(new Dept(3, "部门3", new Date()));
        return depts;
    }

    @GetMapping("/{id}")
    public Dept getParamsRestful(@PathVariable("id") Integer id) {
        return new Dept(id, "部门1", new Date());
    }

    /**
     * @param dept
     * @RequestBody: 将请求体中的数据转换为对象
     */
    @PostMapping("/getPostParams")
    public void getParamsRestful(@RequestBody Dept dept) {
        System.out.println("dept:" + dept);
    }

    @GetMapping("getByName")
    public List<Dept> getByName(String name) {
        System.out.println("部门的名称为：" + name);
        List<Dept> depts = new ArrayList<>();
        depts.add(new Dept(1, "部门1", new Date()));
        depts.add(new Dept(2, "部门2", new Date()));
        depts.add(new Dept(3, "部门3", new Date()));
        return depts;
    }


}
